package com.sh.apiorder.service.impl;

import com.google.gson.Gson;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessagePostProcessor;
import org.springframework.stereotype.Service;

@Service
public class MessageSenderService {

    @Autowired
    private JmsTemplate jmsTemplate;

    @Autowired
    private Queue delayQueue;



    public void sendMessage(Object obj, Long delay) {
        Gson gson = new Gson();
        String message = gson.toJson(obj);
        jmsTemplate.convertAndSend(delayQueue, message, postProcessor -> {
            postProcessor.setLongProperty("AMQ_SCHEDULED_DELAY",  delay);
            return postProcessor;
        });
        System.out.println("发送成功");
    }
}